function addUrlParam(url,name,value){
    url += url.indexOf('?') === -1 ? '?' : '&';
    url += encodeURIComponent(name)+'='+encodeURIComponent(value);
    return url;
}
let url = 'https://www.baidu.com'
let url1 = 'https://www.sogou.com?name=zz'
console.log(addUrlParam(url,'desc','hello world'));
console.log(addUrlParam(url,'desc','helloworld'));
console.log(addUrlParam(url1,'desc','hello world'));